<?php
/*
TestLink Open Source Project - http://testlink.sourceforge.net/
$Id: migrate_16_to_17.php,v 1.23 2009/06/30 10:59:23 havlat Exp $ 

20070515 - franciscom - 
improved controls on source db version

20070317 - franciscom - BUGID 738

*/
require_once(dirname(__FILE__) . "/../../config.inc.php");
require_once(dirname(__FILE__) . '/../../lib/functions/database.class.php' );
require_once(dirname(__FILE__) . "/../../lib/functions/common.php");
require_once(dirname(__FILE__) . "/../../lib/functions/assignment_mgr.class.php");
//require_once(dirname(__FILE__) . "/../installUtils.php");
require_once("migrate_jira_to_tl_functions.php");
require_once("JMigrator.php");
require_once("config_db.jira.inc.php");

define('ADODB_ERROR_LOG_TYPE',3); 
define('PRINT_LEVEL', 'HIDDEN');	
// 20080114 - asielb - fix for bug 1244
// 200804 - havlatm fixed wrong compare
if (mb_strtolower(substr(PHP_OS, 0, 3)) == "win")
{
	define('ADODB_ERROR_LOG_DEST','C:/testlink_errors.log');
}
else
{
	 define('ADODB_ERROR_LOG_DEST','/tmp/testlink_errors.log');
}
require_once(dirname(__FILE__) . '/../../third_party/adodb/adodb-errorhandler.inc.php'); 


$db_cfg['source']=array('db_type' => 'mysql',
                        'db_server' => JIRA_DB_HOST,
                        'db_name'   => JIRA_DB_NAME,
                        'db_admin_name' => JIRA_DB_USER,
                        'db_admin_pass' => JIRA_DB_PASS);
                        
$db_cfg['target']=array('db_type' => 'mysql',
                        'db_server' => DB_HOST,
                        'db_name'   => DB_NAME,
                        'db_admin_name' => DB_USER,
                        'db_admin_pass' => DB_PASS);
// SOURCE DB
print_msg("<span>Connecting to Jira (source) database -" .
          " {$db_cfg['source']['db_name']} - </span>");

$source_db = connect_2_db($db_cfg['source']);

// TARGET DB                        
print_msg("<span>Connecting to Testlink 1.9 Beta5 (target) database. - " .
          "{$db_cfg['target']['db_name']}  - </span>");
$target_db = connect_2_db($db_cfg['target']);

// make sure we have a connection to both dbs
if( is_null($source_db) || is_null($target_db) )
{
  echo "<p>FATAL ERROR: Could not connect to either source or target db!</p>";
  exit();
}

// Create our Migrator Object
$migrate = new JMigrator($source_db, $target_db);

if(false == determine_mysql_version($source_db) || false == determine_mysql_version($target_db))
{
	print_msg("<br /><b>You appear to be using a version of older than version 5 this may not work!</b><br />");
}
else
{
	print_msg("<br />mysql version looks ok<br />");
}

// Do the Jira To Testlink full migration
$migrate->jira_requirements_migration();

//---FINISHED WITH MIGRATION---
?>

